package demoMod.invincibleOne.patches;

import basemod.helpers.CardModifierManager;
import basemod.patches.com.megacrit.cardcrawl.cards.AbstractCard.CardModifierPatches;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.rooms.AbstractRoom;
import demoMod.invincibleOne.cards.invincible.LeechSeed;
import demoMod.invincibleOne.enums.CardTagsEnum;

public class CardModifierPatchPatch {
    @SpirePatch(
            clz = CardModifierPatches.CardModifierAtEndOfTurn.class,
            method = "Postfix"
    )
    public static class PatchCardModifierAtEndOfTurn {
        public static void Postfix(AbstractCreature creature) {
            AbstractPlayer p = AbstractDungeon.player;
            if (creature == p) {
                for (AbstractCard c : p.exhaustPile.group) {
                    CardModifierManager.atEndOfTurn(c, p.exhaustPile);
                }
            }
        }
    }

    @SpirePatch(
            clz = CardModifierPatches.CardModStartBattleHook.class,
            method = "Insert"
    )
    public static class PatchCardModStartBattleHook {
        public static void Postfix(AbstractRoom room) {
            for (AbstractCard c : AbstractDungeon.player.masterDeck.group) {
                if (c.hasTag(CardTagsEnum.ALERT) || c instanceof LeechSeed) {
                    CardModifierManager.onBattleStart(c);
                }
            }
        }
    }
}
